package com.rxt.thermopro.viewmodel

import androidx.lifecycle.MutableLiveData
import com.app.common.viewmodel.BaseViewModel
import com.rxt.thermopro.app.LocalDataDao
import com.rxt.thermopro.bean.ProfileBean

class ProfileViewModel : BaseViewModel() {

    val profileListData: MutableLiveData<MutableList<ProfileBean>> = MutableLiveData()
    val profileHeardData: MutableLiveData<ProfileBean> = MutableLiveData()

    fun initProfileData(profileName: String) {
        val list = mutableListOf<ProfileBean>()
        val currentList = LocalDataDao.INSTANCE.getCurrentProfileList()

        println("123 ->  initProfileData defaultList=$currentList")

        val bean9 = ProfileBean("AddButton", "", mutableListOf())
        list.addAll(currentList)
        list.add(bean9)

        list.forEach {
            it.checked = it.name == profileName
        }
        val headerBean = LocalDataDao.INSTANCE.getProfileHeader()
        if (list.none { it.checked }) {
            headerBean.checked = true
        }
        profileHeardData.value = headerBean
        profileListData.value = list
    }


    fun initProfileData(profileName: String, isSignalTemp: Boolean) {
        val list = mutableListOf<ProfileBean>()
        val currentList = LocalDataDao.INSTANCE.getCurrentProfileList()

        println("123 ->  initProfileData defaultList=$currentList")

        val bean9 = ProfileBean("AddButton", "", mutableListOf())
        if (isSignalTemp) {
            list.addAll(currentList.filter { it.singleTemp })
        } else {
            list.addAll(currentList)
        }
        list.add(bean9)

        list.forEach {
            it.checked = it.name == profileName
        }
        val headerBean = LocalDataDao.INSTANCE.getProfileHeader()
        if (list.none { it.checked }) {
            if (isSignalTemp) {
                list.first().checked = true
            } else {
                headerBean.checked = true
            }
        }
        profileHeardData.value = headerBean
        profileListData.value = list
    }

}